

//
//  FirstController.m
//  UI12-QQ-xib
//
//  Created by 韩旭 on 16/7/30.
//  Copyright © 2016年 lanou. All rights reserved.
//

#define kWidth [UIScreen mainScreen].bounds.size.width
#define kHeight [UIScreen mainScreen].bounds.size.height

#define WIDETH self.view.frame.size.width
#define HEIGHT self.view.frame.size.height
#define COLORAUTO [UIColor colorWithRed:(arc4random()%256/255.0) green:(arc4random()%256/255.0) blue:(arc4random()%256/255.0) alpha:1.0]
#import "Masonry.h"
#import "FirstController.h"
#import "HX_CustomView.h"
#import "SliderView.h"
#import <AVFoundation/AVFoundation.h>
#import <AVKit/AVKit.h>
#import "AudioPlayerManager.h"
@interface FirstController ()<AVAudioPlayerDelegate, AudioPlayerManagerDelegate>
@property (nonatomic, strong) HX_CustomView *hx_custom;
@property (nonatomic, strong) AVPlayer *avplayer;

@property (nonatomic, strong) AVAudioPlayer *player;
@property (nonatomic, strong) SliderView *sliderView;
@property (nonatomic, strong) AudioPlayerManager *audioPlayerManger;
@end

@implementation FirstController

+ (FirstController *)shareDetailViewController {
    static FirstController *first = nil;
    static dispatch_once_t once;
  dispatch_once(&once, ^{
      first = [[FirstController alloc] init];
  });
    return first;
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.audioPlayerManger = [AudioPlayerManager shareAudioPlayerManager];
        self.audioPlayerManger.delegate = self;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor redColor];

//    NSURL *url = [NSURL URLWithString:@"http://sc1.111ttt.com/2016/1/08/20/201201356449.mp3"];
//    AVPlayerItem *item = [[AVPlayerItem alloc] initWithURL:url];
//    self.avplayer = [[AVPlayer alloc] initWithPlayerItem:item];
[self.audioPlayerManger playerPlayWithUrl:@"http://audio.xmcdn.com/group14/M06/55/F3/wKgDZFW87eeieeWPAKWKIhpBNk8680.mp3"];
    
 HX_CustomView *hx_view = [[[NSBundle mainBundle] loadNibNamed:@"HX_CustomView" owner:self options:nil] firstObject];
    
    __weak FirstController *first = self;
  [hx_view playBlockPlayerBtn:^(UIButton *btnPlayer) {
      
      [first.audioPlayerManger play];
      [first.sliderView addPlayerTimer];
      
      
  } StopBtn:^(UIButton *btnStopBtn) {
      [_player stop];
  }];
    
//    self.sliderView = [[SliderView alloc] init];
//    [self.view addSubview:_sliderView];
//    [self.sliderView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.view).with.offset(10);
//        make.height.mas_equalTo(40);
//        make.right.equalTo(self.view).with.offset(-10);
//        make.bottom.equalTo(self.view).with.offset(-170);
//    }];
    
//    
//    [self.sliderView changeSliderValue:^(CGFloat value) {
////        float value = CMTimeGetSeconds()
//        
//    }];
//    
//    [self.sliderView sliderThumb:@"player_slider_playback_thumb" maximumTrackImage:@"player_slider_playback_right" minimumTrackImage:@"player_slider_playback_left"];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
